/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.refunite.mobile.s60.widget;

import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import org.javarosa.core.model.Constants;
import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.QuestionDef;
import org.javarosa.core.model.data.StringData;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryPrompt;

/**
 *
 * @author I040022
 */
public class SimpleQuestionWidget extends AbstractFormWidget{

    protected TextField inputField;
    protected Displayable displayable;

    public SimpleQuestionWidget(FormEntryController formEntryController, FormEntryPrompt formEntryPrompt, int index) {
        super(formEntryController, formEntryPrompt, index);
        int inputMode = TextField.ANY;
        int inputLength = 256;
        switch(formEntryPrompt.getDataType()){
            case Constants.DATATYPE_INTEGER:
                inputMode = TextField.DECIMAL;
                inputLength = 6;
                break;
            default:
                inputMode = TextField.ANY;
                inputLength = 256;
                break;
        }
        this.inputField = new TextField("", null, inputLength, inputMode);
        this.append(this.inputField);
    }
    
    public void saveAnswer() {
        StringData answer = new StringData(inputField.getString());
        this.formEntryController.answerQuestion(formEntryPrompt.getIndex(), answer);
    }

}
